package com.example.chenzhiran.myapplication7;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class MyActivity extends AppCompatActivity {

    //我的点赞和我的购买按钮
    private Button mMyLikeButton;
    private Button mMyPurchaseButton;
    //底部的两个按钮
    public ImageButton mSearchButton;
    private ImageButton mLikeButton;

    String username = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        setTitle("我的页面");

        //前一页面传递信息
        Intent intent = getIntent();
        if (intent != null) {
            username = intent.getStringExtra("username");
        }

        //找到按钮
        mMyLikeButton = (Button)this.findViewById(R.id.my_like_info_button);
        mMyPurchaseButton = (Button)this.findViewById(R.id.my_buy_info_button);
        mSearchButton = (ImageButton)this.findViewById(R.id.search_layout_imageButton);
        mLikeButton = (ImageButton)this.findViewById(R.id.like_layout_imageButton);

        //设置点击事件
        mMyLikeButton.setOnClickListener(mOnClickListener);
        mMyPurchaseButton.setOnClickListener(mOnClickListener);
        mSearchButton.setOnClickListener(mOnClickListener);
        mLikeButton.setOnClickListener(mOnClickListener);
    }

    //点击事件
    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch(v.getId()) {
                //点赞按钮
                case R.id.my_like_info_button:
                    Intent intent = new Intent(MyActivity.this, MyLikeActivity.class);
                    intent.putExtra("username",username);
                    startActivity(intent);
                    break;

                //购买按钮
                case R.id.my_buy_info_button:
                    Intent intent1 = new Intent(MyActivity.this, PurchasedActivity.class);
                    intent1.putExtra("username",username);
                    startActivity(intent1);
                    break;

                //底部跳转按钮
                case R.id.search_layout_imageButton:
                    Intent intent2 = new Intent(MyActivity.this, ProductActivity.class);
                    startActivity(intent2);
                    break;
                case R.id.like_layout_imageButton:
                    Intent intent3 = new Intent(MyActivity.this, PurchaseActivity.class);
                    startActivity(intent3);
                    break;
            }

        }
    };
}
